package com.cloudsigns.factorymanager2.engineering.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.bean.MediaBean;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;
import com.cloudsigns.factorymanager2.project.myinerface.ItemRemoveListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tony on 2018/5/26.
 */

public class MediaForPublicationAdapter extends BaseAdapter {
    private Context context;
    private List<MediaBean> datas = new ArrayList<MediaBean>();
    private LayoutInflater inflater;
    private String tag = "";
    private ItemClickListener itemClickListener;


    public MediaForPublicationAdapter(Context context, String tag) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.tag = tag;
    }

    public void setItemClickListener(ItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }


    public void setData(List<MediaBean> list) {
        this.datas.clear();
        if (null != list) {
            this.datas.addAll(list);
        }

    }


    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public MediaBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_media_for_publication, null);
            holder.tv_top = convertView.findViewById(R.id.tv_top);
            holder.tv_status = convertView.findViewById(R.id.tv_status);
            holder.tv_bottom = convertView.findViewById(R.id.tv_bottom);


            holder.rl_item = convertView.findViewById(R.id.rl_item);


            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();

        }

        MediaBean mediaBean = datas.get(position);

        holder.rl_item.setTag(mediaBean);
        holder.tv_top.setText(mediaBean.getMediaName());
        holder.tv_bottom.setText(mediaBean.getNumber());

        if (mediaBean.getStatus() == CommonEnum.MediaStatus.PROCESSING) {
            holder.tv_status.setText("");
//            holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_FFC000));
//            holder.tv_status.setText("[反馈中]");
        } else if (mediaBean.getStatus() == CommonEnum.MediaStatus.PAUSE) {
            holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_c64149));
            holder.tv_status.setText("[暂停]");

        } else if (mediaBean.getStatus() == CommonEnum.MediaStatus.PROBLEM_APPEAR) {
            holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_c64149));
            holder.tv_status.setText("[出现问题]");

        } else if (mediaBean.getStatus() == CommonEnum.MediaStatus.PROBLEM_FEEDBACK) {
            holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_FCD505));
            holder.tv_status.setText("[等待确认]");
        } else if (mediaBean.getStatus() == CommonEnum.MediaStatus.COMPLETE_FEEDBACK) {
            holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_FCD505));
            holder.tv_status.setText("[等待确认]");
//            holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_FF0000));
//            holder.tv_status.setText("[上刊后反馈]");
        } else if (mediaBean.getStatus() == CommonEnum.MediaStatus.COMPLETE) {
            holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_74BF73));
            holder.tv_status.setText("[完结]");
        }



        holder.rl_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != itemClickListener)
                    itemClickListener.itemClick(view, position);
            }
        });

        return convertView;
    }

    private class ViewHolder {
        private TextView tv_top;
        private TextView tv_status;
        private TextView tv_bottom;
        private View rl_item;

    }
}
